using System;
using System.Collections.Generic;
using System.Text;

namespace OurMediaPlayer.Logic.Filters
{
    class NegativoFilter: Filter
    {
        public NegativoFilter()
        { 
        
        }

        public override void Process(byte[] source, IntPtr destination, MediaInfo videoInfo)
        {
            unsafe
            {
                byte* b = (byte*)destination;

                int width, height;

                if (this.Complete)
                {
                    width = videoInfo.MediaWidth;
                    height = videoInfo.MediaHeight;
                    
                } else {
                    width = Math.Abs(this.Xmax - this.Xmin);
                    height = Math.Abs(this.Ymax - this.Ymin);
                    
                    int ymin = Math.Min(this.Ymax, this.Ymin);
                    int xmin = Math.Min(this.Xmax, this.Xmin);

                    b += ymin * videoInfo.MediaStride + xmin * 3;
                }

                int nOffset = videoInfo.MediaStride - width * 3;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        b[0] ^= 0xff;
                        b[1] ^= 0xff;
                        b[2] ^= 0xff;
                        b += 3;
                    }

                    b += (nOffset);
                }
            }
        }
    }
}
